home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / BBS-Archive / Util / Commodities / DFA-25.lha / DFA-25 / Archive / DFA.lha / Rexx / insert_adrletter.ced < prev    next >
Text File  |  1995-05-25  |  5KB  |  199 lines

  1. /* $Revision Header built automatically *************** (do not edit) ************
  2. **
  3. ** © Copyright by Dirk Federlein
  4. **
  5. ** File             : insert_adrletter.ced
  6. ** Created on       : Monday, 04.04.94 17:50:55
  7. ** Created by       : Dirk Federlein
  8. ** Current revision : V2.1
  9. **
  10. **
  11. ** Purpose
  12. ** -------
  13. **
  14. ** Inserts an address into an already done letter head.
  15. **
  16. ** You may use the following fill-ins, when creating your
  17. ** letter head template:
  18. **     - <Date>
  19. **     - <Salutation>
  20. **     - <First>
  21. **     - <Name>
  22. **     - <Street>
  23. **     - <ZIP>
  24. **     - <City>
  25. **     - <Country>
  26. **
  27. ** You may write the part of the desired address anywhere to the
  28. ** letter head template. It is deleted by the script, before the
  29. ** parts of the address are inserted!
  30. **
  31. ** -------------------------------------------------------------------
  32. **
  33. ** rewritten by Kai Stuke @ 2:240/605.3 (22.05.93)
  34. **
  35. **     Now you can use every template as often as you want. Kai Stuke
  36. **     found another way to do multiple replaces (CED Multiple replace
  37. **     is buggy) which is much better than my solution has been.
  38. **
  39. **     Thanks Kai!
  40. **
  41. ** -------------------------------------------------------------------
  42. **
  43. ** Lookup part taken from:
  44. **
  45. ** LookUp.ced                         Copyright (c) 1989, Peter Cherna
  46. **
  47. ** ARexx program for CygnusEd Professional that looks up the word under
  48. ** the cursor.
  49. **
  50. ** Version 1.30:  August 20, 1989        Release 1.2:  August 29, 1989
  51. **
  52. ** -------------------------------------------------------------------
  53. **
  54. ** Revision V2.1
  55. ** --------------
  56. ** created on Monday, 04.04.94 17:56:43  by  Dirk Federlein.   LogMessage :
  57. **   - The replace command of CED did only replace the first
  58. **     WORD of the string. Fixed.
  59. **
  60. ** Revision V2.0
  61. ** --------------
  62. ** created on Monday, 04.04.94 17:50:55  by  Dirk Federlein.   LogMessage :
  63. **     --- Initial release ---
  64. **
  65. *********************************************************************************/
  66.  
  67. options results
  68.  
  69. address 'rexx_ced'
  70.  
  71. tabchar = '09'X
  72. cr    = '0A'X
  73. quote    = '22'X
  74.  
  75.  
  76. /*    Get contents of current line: */
  77. status 55
  78. line = result
  79.  
  80. /*    Get tab size: */
  81. status 8
  82. tabadjust = result - 1
  83.  
  84. /*    Get cursor x position (relative to beginning of line = 1): */
  85. status 46
  86. cur = result + 1
  87.  
  88. i = index(line,tabchar)
  89. DO while i > 0 & i <= cur - tabadjust
  90.     cur = cur - tabadjust
  91.     i = index(line,tabchar,i+1)
  92. END
  93.  
  94. /*    If the current character is non-alphabetic, then start one character
  95.     over to the left.  This allows the cursor to be immediately after
  96.     the key word (say on a space or bracket.) */
  97.  
  98. char = substr(line,cur,1)
  99. if (~(datatype(char,'A') | char = '_') & cur > 1) then
  100.     cur = cur - 1
  101.  
  102. /*    Find leftmost and rightmost alphabetic character adjacent to current: */
  103.  
  104. right = cur - 1
  105. left = cur + 1
  106. char = 'A'
  107. DO while (datatype(char,'A') | char = '_') & (left > 0)
  108.      left = left - 1
  109.     if left > 0 then
  110.         char = substr(line,left,1)
  111. END
  112. char = 'A'
  113. DO while (datatype(char,'A') | (char = '_'))
  114.     right = right + 1
  115.     char = substr(line,right,1)
  116. END
  117.  
  118. if right-left <= 1 then
  119. DO
  120.     getstring
  121.     target = result
  122.     if (target = 'RESULT') then
  123.         exit
  124. END
  125. else
  126. DO
  127.     target = substr(line,left+1,right-left-1)
  128.     newtarget = '#?'target'#?'
  129. END
  130.  
  131.  
  132. DO
  133.  say 'Searching for address' newtarget '...'
  134.  
  135.  if ~show(ports, DFA) then
  136.  do
  137.   'okay1' 'You should have DFA running, if you' cr 'want to get an
  138. address
  139.         from it!' exit 0
  140.  end
  141.  
  142.  
  143.  address 'DFA' "SEARCH" newtarget "IGNORECASE ALL STEM ADR."
  144.  
  145.  if rc=0 then
  146.  do
  147.       /* initalization of replacement strings */
  148.       rep.0.old = "<Salutation>"   /* string to search for */
  149.       rep.0.new = adr.address.0 /* what it should be replaced with */
  150.  
  151.       rep.1.old = "<First>"
  152.       rep.1.new = adr.address.1
  153.  
  154.       rep.2.old = "<Name>"
  155.       rep.2.new = adr.address.2
  156.  
  157.       rep.3.old = "<Street>"
  158.       rep.3.new = adr.address.4
  159.  
  160.       rep.4.old = "<ZIP>"
  161.       rep.4.new = adr.address.5
  162.  
  163.       rep.5.old = "<City>"
  164.       rep.5.new = adr.address.6
  165.  
  166.       rep.6.old = "<Country>"
  167.       rep.6.new = adr.address.7
  168.  
  169.       rep.7.old = "<Date>"
  170.       rep.7.new = date('e')
  171.  
  172.       repitems = 7
  173.  
  174.   "Prev WORD"
  175.   "Mark BLOCK"
  176.   "NEXT WORD"
  177.   "CUT BLOCK"
  178.  
  179.   do i=0 to repitems
  180.    "Beg of File"
  181.  
  182.    do until xpos1 = xpos2 & ypos1 = ypos2
  183.     'status' 44
  184.     xpos1 = result
  185.     'status' 45
  186.     ypos1 = result
  187.     "Replace" rep.i.old quote||rep.i.new||quote
  188.     'status' 44
  189.     xpos2 = result
  190.     'status' 45
  191.     ypos2 = result
  192.    end
  193.   end
  194.  end
  195.  else
  196.   'okay1' 'Could not find address of' newtarget '! ' END
  197.  
  198. exit
  199.